#include"server.hpp"
#define HOST "127.0.0.1"
#define USER "root"
#define PASS "s@057931"
#define DBNAME "gobang"

void test_mysql()
{
    MYSQL* mysql=mysql_util::mysql_create("127.0.0.1","root","s@057931","gobang");
    bool ret=mysql_util::mysql_exec(mysql,"insert into stu values(NULL,'小黑',4,10,10,10)");
    if(ret==false)
        return;
    mysql_util::mysql_destory(mysql);
}
void test_json()
{
    Json::Value val;
    val["姓名"]="张三";
    val["年龄"]=18;
    std::string str;
    json_util::Serialize(val,str);
    std::cout<<str<<std::endl;
    Json::Value deval;
    json_util::UnSerialize(deval,str);
    std::cout<<"姓名:"<<deval["姓名"].asString()<<std::endl;
    std::cout<<"年龄:"<<deval["年龄"].asInt()<<std::endl;
}

void test_split()
{
    std::string src="123,,,12,456,55,";
    std::vector<std::string> vec;
    string_util::split(src,",",vec);
    for(auto& e:vec)
        INFO_LOG("%s\n",e.c_str());
}

void test_file()
{
    std::string str;
    file_util::read("file.txt",str);
    INFO_LOG("读取到文件数据:\n%s\n",str.c_str());
}

void db_test()
{
    user_table ut(HOST,USER,PASS,DBNAME,3306);
    ut.lose(1);
}

void onlie_test()
{
    online_manager om;
    websocket_server::connection_ptr conn;
    uint64_t uid=2;
    om.enter_game_room(uid,conn);
    if(om.is_game_room(uid))
        INFO_LOG("%ld进入游戏房间",uid);
    om.exit_game_room(uid);
    if(om.is_game_room(uid)==false)
        INFO_LOG("%ld不在游戏房间",uid);
}

void room_test()
{
    user_table ut(HOST,USER,PASS,DBNAME,3306);
    online_manager om;
    room_manager rm_manager(&om,&ut);
    rm_manager.create_room(10,20);
}

void test_matcher()
{
    user_table ut(HOST,USER,PASS,DBNAME,3306);
    online_manager om;
    room_manager ma(&om,&ut);
    matcher matcher_t(&ut,&ma,&om);
}

void test_server()
{
    gobang_server server("./wwwroot",HOST,USER,PASS,DBNAME,3306);
    server.start(9090);
}

int main()
{
    test_server();
    //DEBUG_LOG("服务器退出");
    return 0;
}